﻿<%@ Application Language="C#" %>
<%@ Import Namespace="BONSAI.DAL"%>
<%@ Import Namespace="BONSAI.Common"%>
<%@ Import Namespace="System.Collections.Generic"%>
<%@ Import Namespace="BONSAI.Common.DTO"%>
<%@ Import Namespace="System.Web.Routing"%>

<script runat="server">
    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        RegisterRoutes();
        Application[BONSAIConstants.LISTALLTYPE] = BindContant();
        Application[BONSAIConstants.LISTPRODUCTSNEW] = GetNew();
    }

    public IList<TypeProductsDTO> BindContant()
    {
        return (new TypeProductsDAO()).GetAll();
    }
    public IList<ProductsDTO> GetNew()
    {
        return (new ProductsDAO()).GetNew(true);
    }

    private static void RegisterRoutes()
    {
        try
        {
            RouteTable.Routes.Add("news", new Route("news"
                                                      , new RouteHandler("~/Pages/news.aspx")));
            RouteTable.Routes.Add("home", new Route("home/{*typeId}"
                                                    , new RouteHandler("~/Pages/home.aspx")));
            RouteTable.Routes.Add("home-detail", new Route("home-detail/{*productId}"
                                                    , new RouteHandler("~/Pages/home-detail.aspx")));
            
            RouteTable.Routes.Add("search", new Route("search/{typeId}/{*name}"
                                                    , new RouteHandler("~/Pages/search.aspx")));
           
            RouteTable.Routes.Add("news-detail", new Route("news-detail/{newsId}/{*title}"
                                                           , new RouteHandler("~/Pages/news-detail.aspx")));
            RouteTable.Routes.Add("contacts", new Route("contacts"
                                                       , new RouteHandler("~/Pages/contact.aspx")));
            
            RouteTable.Routes.Add("payment", new Route("payment"
                                                       , new RouteHandler("~/Pages/payment.aspx")));

            RouteTable.Routes.Add("aboutus", new Route("aboutus"
                                                       , new RouteHandler("~/Pages/AboutUs.aspx")));

            RouteTable.Routes.Add("service", new Route("service"
                                                       , new RouteHandler("~/Pages/Services.aspx")));

            RouteTable.Routes.Add("home-cart", new Route("home-cart"
                                                         , new RouteHandler("~/Pages/home-cart.aspx")));

            RouteTable.Routes.Add("404", new Route("404"
                                                   , new RouteHandler("~/Pages/NotePage.aspx")));

            RouteTable.Routes.Add("ajax", new Route("ajax/{callback}/{aboutUsId}"
                                                    , new RouteHandler("~/ajax/Getdata.aspx")));
        }
        catch (Exception e)
        {
            e.ToString();
            // HttpContext.Current.Response.Redirect(LPConstants.ERROR404);
        }
        //RouteTable.Routes.Add("home",
        //        new Route("home/{name,aaa}",new UserRouteHandler("~/Default.aspx")));

        //RouteTable.Routes.Add("home",
        //                      new Route("home/{name}", new RouteValueDictionary(new { name = "Vi-VI" }),
        //                                new UserRouteHandler("~/Default.aspx")));


        //System.Web.Routing.RouteTable.Routes.Add(
        //        "Default2User", new System.Web.Routing.Route("Default2User/{name}",
        //       new UserRouteHandler("~/Default2.aspx")));

        //System.Web.Routing.RouteTable.Routes.Add(
        //        "aa", new System.Web.Routing.Route("aa/{name}",
        //        new UserRouteHandler("~/Default3.aspx")));

        //System.Web.Routing.RouteTable.Routes.Add(
        //        "bbb", new System.Web.Routing.Route("bbb/{name}/{name1}",
        //        new UserRouteHandler("~/Default4.aspx")));



        //var myPopup = new DataSet();
        //myPopup.ReadXml(HttpContext.Current.Server.MapPath("~/xml/routing.xml"));
        //var myDataTable = myPopup.Tables[0];

        //for (var i = 0; i < myDataTable.Rows.Count; i++)
        //{
        //    if (myDataTable.Rows[i][0].ToString().Equals("false"))
        //    {
        //        System.Web.Routing.RouteTable.Routes.Add(
        //                myDataTable.Rows[i][1].ToString(), new System.Web.Routing.Route(myDataTable.Rows[i][2].ToString(),
        //                                                             new RouteHandler(myDataTable.Rows[i][3].ToString())));    
        //    }
        //    else
        //    {
        //        System.Web.Routing.RouteTable.Routes.Add(
        //                myDataTable.Rows[i][1].ToString(), new System.Web.Routing.Route(myDataTable.Rows[i][2].ToString(),
        //                                                             new UserRouteHandler(myDataTable.Rows[i][3].ToString())));   
        //    }

        //}



    }

   
    void Application_End(object sender, EventArgs e) 
    {
        //  Code that runs on application shutdown

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e) 
    {
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }
       
</script>
